/***************************
新增or编辑
* */
<template>
  <el-dialog
    :title="dialogTitle"
    :close-on-click-modal="false"
    :visible.sync="visible"
    top="8vh"
    @close="closeDialog()"
    width="40vw"
  >
    <div class="boxsty">
      <el-form
        ref="dataForm"
        :rules="formRules"
        :model="dataForm"
        label-width="100px"
        @keyup.enter.native="dataFormSubmit()"
      >
        <el-row>
          <el-form-item label="统计名称:" prop="tjmc">
            <el-input v-model="dataForm.tjmc" placeholder="统计名称" style="width:80%"></el-input>
          </el-form-item>
        </el-row>

        <el-form-item label="备注:" prop="bz">
          <el-input type="textarea" :rows="4" v-model="dataForm.bz" placeholder="备注"  max-length="10"></el-input>
        </el-form-item>

       <!-- <el-form-item label="领导:" prop="ldusers">
          <el-button icon="el-icon-user-solid" @click="showPerson" type="text"></el-button>
          <span v-for="it in optionsd" :key="it.userId">
              <el-tooltip
                class="item"
                :disabled="optionsd.length < 3"
                effect="dark"
                placement="top-start"
              >
                <span style="font-size: 16px; color: #303745">{{ it.userName }}、</span>
              </el-tooltip>
            </span>
        </el-form-item>-->
      </el-form>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" plain @click="closeDialog()">返回</el-button>
      <el-button type="primary" plain @click="handleConfirm">确定</el-button>
    </span>
    <!--<UserCommonSelect v-if="usercomment" ref="usercomment"   @submitfy="submitfy"></UserCommonSelect>-->
  </el-dialog>

</template>

<script>
/*import UserCommonSelect from "@/views/statisticsanalysis/components/usercomment-select-ld";//人员选择的组件*/
// 接口 api
import {
    addAssess,
    updateAssess

} from "@/api/statisticsanalysis/assessApi.js";

export default {

  data() {
   /* var validateLdusers = (rule, value, callback) => {
        if (this.optionsd.length === 0) {
            callback(new Error("请选择领导"));
        }else{
            callback();
        }
    };*/
    return {
      dialogTitle: "新增",
      visible: false,
      dataForm: {
        //数据表单
        /*ldusers: []*/
      },
     /* optionsd: [], //被考核人的数组*/
      usercomment: false, //人员组件显隐
      ldList:[],
      formRules: {
        tjmc: [{ required: true, message: "请输入统计名称", trigger: "blur" }],
        bz: [{ required: true, message: "请输入备注", trigger: "blur" }],
       /* ldusers: [{ required: true, validator: validateLdusers, trigger: "blur" }],*/

      },

    };
  },
  components: {
     /* UserCommonSelect*/
  },
  created() {
  },
  methods: {

    // 初始化
    init(data) {
      if (data != undefined) {
        this.dataForm = data;
        this.dialogTitle = "编辑";
      } else {

      }
      this.visible = true;
    },
    //监听被考核人变化，去掉提示
   /* optionsd: {
        handler(val) {
            // 监听放在这个回调里面，不然会报错
            this.$nextTick(() => {
                this.$refs["dataForm"].clearValidate();
            });
        },
        deep: true
    },*/
    //   人员展示
    /*showPerson() {
        this.usercomment = true;
        this.$nextTick(() => {
            this.$refs.usercomment.init("12", "sjkh", JSON.stringify(this.optionsd),"","htcj");  //fakeData

        });

    },*/
    //筛选出姓名与职务
    shaiXuan(data, type) {
        var list = [],
            obj = {};
        if (type == "领导") {
            for (var i in data) {
                list.push(data[i].userName);
            }
        }
        return list.toString();
    },
   /* // 选择人后的提交
    submitfy(data) {console.log(data)
            this.optionsd = data.tableDataUser;
            this.personSelectChange();

    },*/
    // 被考核人改变
    /*personSelectChange(data) {
        this.ldList = [];
        this.optionsd.map(it => {
            this.ldList.push(it.userName);
           /!* this.ldList.push({
                assessDeptId: it.deptId,
                assessDeptName: it.deptName,
                assessRealName: it.userName,
                assessUserId: it.userId,
                assessUserName: it.userCode
            });*!/
        });
    },*/
  // 确定
    handleConfirm() {

        this.$refs.dataForm.validate(valid => {
            console.log(valid)
            if (valid) {
                this.dataForm.isld = '1';
              /*  this.dataForm['ldusers'] = this.ldList;*/
                if (this.dataForm.id) {
                    updateAssess(Object.assign(this.dataForm))
                        .then(r => {
                            if (r.data.code == 0) {
                                this.$message.success("编辑成功");
                                this.$emit("refreshDataList");
                                this.closeDialog();
                            } else {
                                this.$message.error(r.data.msg);
                            }
                        })
                        .catch(err => {});
                } else {

                    addAssess(Object.assign(this.dataForm))
                        .then(r => {
                            if (r.data.code == 0) {
                                this.$message.success("新增成功");
                                this.$emit("refreshDataList");
                                this.closeDialog();
                            } else {
                                this.$message.error(r.data.msg);
                            }
                        })
                        .catch(err => {});
                }
            } else {
                console.log("error submit!!");
                return false;
            }
        });
    },
    // 表单提交
    dataFormSubmit() {},
    // 关闭
    closeDialog() {
      this.visible = false;
      this.$emit("closeDialog");
    }
  }
};
</script>

<style>
</style>
